home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / copymove.swg / 0003_Copy File #3.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-05-28  |  1.1 KB  |  59 lines

  1. {
  2. > Or can someone put up some Procedure that will copy Files.
  3. }
  4.  
  5. {$O+}
  6.  
  7. Uses
  8.   Dos;
  9.  
  10. Function CopyFile(SourceFile, TargetFile : String): Byte;
  11. { Return codes:  0 successful
  12.                  1 source and target the same
  13.                  2 cannot open source
  14.                  3 unable to create target
  15.                  4 error during copy
  16. }
  17. Var
  18.   Source,
  19.   Target  : File;
  20.   BRead,
  21.   BWrite  : Word;
  22.   FileBuf : Array[1..2048] of Char;
  23. begin
  24.   If SourceFile = TargetFile then
  25.   begin
  26.     CopyFile := 1;
  27.     Exit;
  28.   end;
  29.   Assign(Source,SourceFile);
  30.   {$I-}
  31.   Reset(Source,1);
  32.   {$I+}
  33.   If IOResult <> 0 then
  34.   begin
  35.     CopyFile := 2;
  36.     Exit;
  37.   end;
  38.   Assign(Target,TargetFile);
  39.   {$I-}
  40.   ReWrite(Target,1);
  41.   {$I+}
  42.   If IOResult <> 0 then
  43.   begin
  44.     CopyFile := 3;
  45.     Exit;
  46.   end;
  47.   Repeat
  48.     BlockRead(Source,FileBuf,SizeOf(FileBuf),BRead);
  49.     BlockWrite(Target,FileBuf,Bread,BWrite);
  50.   Until (Bread = 0) or (Bread <> BWrite);
  51.   Close(Source);
  52.   Close(Target);
  53.   If Bread <> BWrite then
  54.     CopyFile := 4
  55.   else
  56.     CopyFile := 0;
  57. end; {of func CopyFile}
  58.  
  59.